package com.hzw.saas.api.hpc.enums;

import java.util.Objects;

/**
 * 超算任务状态
 *
 * @author zzl
 * @since 02/07/2021
 */
public enum HpcTaskStatus {

    FAILED(-1, "FAILED", "失败"),
    PAUSE(0, "PAUSE", "暂停"),
    PROGRESS(1, "PROGRESS", "正在计算"),
    RUNNING(1, "RUNNING", "正在计算"),
    CANCELLED(2, "CANCELLED", "中断"),
    FINISH(3, "COMPLETED", "计算完成"),
    UNKNOWN(9999, "UNKNOWN", "未知状态"),
    ;

    private final Integer value;
    private final String code;
    private final String text;
    public Integer value() {
        return this.value;
    }
    public String code() {
        return this.code;
    }
    public String text() {
        return this.text;
    }

    HpcTaskStatus(Integer value,String code, String text) {
        this.value = value;
        this.code = code;
        this.text = text;
    }

    public static String text(Integer value) {
        for (HpcTaskStatus hpcTaskStatus : HpcTaskStatus.values()) {
            if (Objects.equals(hpcTaskStatus.value, value)) {
                return hpcTaskStatus.text;
            }
        }
        return null;
    }

    public static HpcTaskStatus instance(Integer value) {
        for (HpcTaskStatus hpcTaskStatus : HpcTaskStatus.values()) {
            if (Objects.equals(hpcTaskStatus.value, value)) {
                return hpcTaskStatus;
            }
        }
        return null;
    }

    public static HpcTaskStatus instance(String code) {
        for (HpcTaskStatus hpcTaskStatus : HpcTaskStatus.values()) {
            if (hpcTaskStatus.code().equalsIgnoreCase(code)) {
                return hpcTaskStatus;
            }
        }
        return HpcTaskStatus.UNKNOWN;
    }

}
